home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / BBS / HERMES / ProtMover6.1.cpt / ASCII / prefs.c < prev    next >
C/C++ Source or Header  |  1990-05-29  |  3KB  |  146 lines

  1. #include "Protocol.h"
  2. #include "ASCII.h"
  3.  
  4. extern ControlHandle GetItemHandle();
  5.  
  6. extern ProtoRecPtr PRP;
  7. extern ProtoGloPtr PGP;
  8.  
  9. doSetPrefs()
  10. {
  11.     int item;
  12.     Str255 text;
  13.     DialogPtr dp;
  14.     GrafPtr savePort;
  15.     GetPort(&savePort);
  16.     /*    set up the preferences dialog */
  17.     dp = GetNewDialog(PRP->procID+0, 0L, -1L);
  18.     SetPort(dp);
  19.     CenterWindow(dp, 1, 1);
  20.     text[0] = 0;
  21.     OSTypeToPstrcat(text, &PGP->thePrefs.fType);
  22.     SetTextItem(3, text, dp);
  23.     SelIText(dp, 3, 0, 32767);
  24.     ShowWindow(dp);
  25.     OutLineItem(1, dp);
  26.     ModalDialog(0L, &item);
  27.     GetTextItem(3, text, dp);
  28.     PstrToOSType(text, &PGP->thePrefs.fType);
  29.     HideWindow(dp);
  30.     DisposDialog(dp);
  31.     SetPort(savePort);
  32.     RWPrefs(TRUE);
  33. }
  34.  
  35. RWPrefs(write)
  36. int write;
  37. {
  38.     register ASCIIPrefPtr app;
  39.     register ASCIIPrefHandle aph;
  40.     aph = (ASCIIPrefHandle) GetResource('DATA', PRP->procID+0);
  41.     if (aph) {
  42.         app = *aph;
  43.         if (PRP->F.B.transMode == BBSMODE) {
  44.             ++app;
  45.         }
  46.         if (write) {
  47.             *app = PGP->thePrefs;
  48.             ChangedResource(aph);
  49.             WriteResource(aph);
  50.         }
  51.         else {
  52.             PGP->thePrefs = *app;
  53.         }
  54.     }
  55.     else {
  56.         PGP->thePrefs.fType = 'ttxt';
  57.     }
  58. }
  59.  
  60. OutLineItem(item, dp)
  61. int item;
  62. DialogPtr dp;
  63. {
  64.     Rect itemBox;
  65.     GetItemRect(item, &itemBox, dp);
  66.     PenSize(3, 3);
  67.     InsetRect(&itemBox, -4, -4);
  68.     FrameRoundRect(&itemBox, 16, 16);
  69.     PenNormal();
  70. }
  71.  
  72. ControlHandle GetItemHandle(item, dp)
  73. register int item;
  74. register DialogPtr dp;
  75. {
  76.     int itemType;
  77.     Rect itemBox;
  78.     ControlHandle itemHandle;
  79.     GetDItem(dp, item, &itemType, &itemHandle, &itemBox);
  80.     return(itemHandle);
  81. }
  82.  
  83. SetTextItem(item, text, dp)
  84. int item;
  85. StringPtr text;
  86. DialogPtr dp;
  87. {
  88.     register ControlHandle itemHandle;
  89.     itemHandle = GetItemHandle(item, dp);
  90.     SetIText(itemHandle, text);
  91. }
  92.  
  93. GetTextItem(item, text, dp)
  94. int item;
  95. StringPtr text;
  96. DialogPtr dp;
  97. {
  98.     register ControlHandle itemHandle;
  99.     itemHandle = GetItemHandle(item, dp);
  100.     GetIText(itemHandle, text);
  101. }
  102.  
  103. OSTypeToPstrcat(s, ostype)
  104. register StringPtr s;
  105. register OsType *ostype;
  106. {
  107.     register int i;
  108.     asm {
  109.                 move.l    s, a0
  110.                 move.b    (s)+, i
  111.                 andi.w    #0x00FF, i
  112.                 adda.w    i, s
  113.                 addq.b    #4, (a0)
  114.                 moveq    #3, i
  115. @loop            move.b    (ostype)+, (s)+
  116.                 dbf        i, @loop
  117.     }
  118. }
  119.  
  120. PstrToOSType(s, ostype)
  121. register StringPtr s;
  122. register OsType *ostype;
  123. {
  124.     register int i;
  125.     asm {
  126.                 clr.l    (ostype)
  127.                 move.b    (s)+, i
  128.                 beq.s    @the_end
  129.                 subq.w    #1, i
  130.                 andi.w    #0x0003, i
  131. @loop            move.b    (s)+, (ostype)+
  132.                 dbf        i, @loop
  133. @the_end        return
  134.     }
  135. }
  136.  
  137. GetItemRect(item, rect, dp)
  138. int item;
  139. Rect *rect;
  140. DialogPtr dp;
  141. {
  142.     int itemType;
  143.     ControlHandle itemHandle;
  144.     GetDItem(dp, item, &itemType, &itemHandle, rect);
  145. }
  146.